package xukj.network;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * @ClassName SocketUtils
 * @Description
 * @Author xukj
 * @Date 2019/1/11 10:11
 * @Version
 */
public class SocketUtils {

    public static Object send(Trans trans) {
        ObjectOutputStream objectOutputStream = null;
        ObjectInputStream inputStreamReader = null;
        try (Socket socket = new Socket("127.0.0.1",9001)){
            objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
            objectOutputStream.writeObject(trans);
            inputStreamReader=new ObjectInputStream(socket.getInputStream());
            return inputStreamReader.readObject();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                objectOutputStream.close();
                inputStreamReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
